<template>
	<yd-layout id='bdComment' class=''>
		<yd-infinitescroll v-show="commentList.length>0" :callback="getLst" ref="infinitescrollDemo">

			<div slot="list" class="list" v-for="item in commentList">
				<img class="list_img" :src="item.avatar" alt="" />
				<div class="list_right">
					<div class="list_name">{{item.nick_name}}</div>
					<div class="list_time">{{item.newTime}}</div>
					<div class="list_label c_size_30_42">{{item.content}}</div>
				</div>
			</div>
			<!-- 数据全部加载完毕显示 -->
			<span slot="doneTip">没有更多数据了~~</span>

			<!-- 加载中提示，不指定，将显示默认加载中图标 -->
			<!--<img slot="loadingTip" src="path/img/loading.svg"/>-->
		</yd-infinitescroll>
		<NoList v-show='commentList.length==0'>
			<img slot='img' src="../../../assets/kong_2.png" alt="" />
		</NoList>
		<yd-backtop></yd-backtop>

	</yd-layout>
</template>

<script>
	import { InfiniteScroll } from 'vue-ydui/dist/lib.rem/infinitescroll';
	import { BackTop } from 'vue-ydui/dist/lib.rem/backtop';
	export default {
		components: {
			[InfiniteScroll.name]: InfiniteScroll,
			[BackTop.name]: BackTop,
		},
		data() {
			return {
				commentList: [],
				pageNum: 1,
				pageCount: 10,
			}
		},
		created() {},
		watch: {

		},
		computed: {

		},
		mounted() {
			document.title = '学员分享'
			this.getLst()
		},
		methods: {
			getLst(){
				this.$root.ajax({
					type:'get',
					name: 'comment/lst',
					params: {
						kind: 200,
						page: this.pageNum,
						count: this.pageCount,
						oid:this.$route.query.oid,
					}
				}).then((d) => {
					let date = new Date()
					for(let a = 0 ;a<d.data.comment_list.length;a++){
						//刚刚
						if(date-d.data.comment_list[a].create_time*1000<60*1000){  //60s
							d.data.comment_list[a].newTime = '刚刚'
						}else if(date-d.data.comment_list[a].create_time*1000<5*60*1000){ //5min
							d.data.comment_list[a].newTime = '5分钟之内'
						}else if(date-d.data.comment_list[a].create_time*1000<30*60*1000){ //30min
							d.data.comment_list[a].newTime = '30分钟之内'
						}else if(date-d.data.comment_list[a].create_time*1000<3*60*60*1000){ //3h
							d.data.comment_list[a].newTime = '3小时之内'
						}else if(date-d.data.comment_list[a].create_time*1000<24*60*60*1000){ //24
							d.data.comment_list[a].newTime = '24小时之内'
						}else {
							let plDate = new Date(d.data.comment_list[a].create_time*1000)
							let month = plDate.getMonth()
							let day = plDate.getDate()
							if(date.getFullYear() == plDate.getFullYear()){
								d.data.comment_list[a].newTime = (month+1 < 10 ? '0' + (month + 1) : (month + 1)) + '-' + (day < 10 ? '0' + day : day)
							}else{
								d.data.comment_list[a].newTime = plDate.getFullYear() + '-' + (month+1 < 10 ? '0' + (month + 1) : (month + 1)) + '-' + (day < 10 ? '0' + day : day) 
							}
						}
					}
					this.commentList = [...this.commentList, ...d.data.comment_list];
					if(this.commentList.length >= d.data.comment_total) {
						/* 所有数据加载完毕 */
						this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
						return;
					}

					/* 单次请求数据完毕 */
					this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.finishLoad');

					this.pageNum++;
				})
			},
		}
	}
</script>

<style lang="scss">
	@import './comment.scss';
</style>